package com.ssy.lingxi.product.entity.material;

import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.ssy.lingxi.product.entity.Goods;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 物料流程规则配置
 * @author 彭冬冬
 * @version 2.0.0
 * @date 2022/3/25 10:24
 */
@Entity
@Table(schema = "public",
        name = "product_material_process",
        indexes = {
        @Index(name = "product_material_process_member_id_idx", columnList = "memberId"),
        @Index(name = "product_material_process_role_id_idx", columnList = "roleId"),
        @Index(name = "product_material_process_name_idx", columnList = "name"),
        @Index(name = "product_material_process_create_time_idx", columnList = "createTime"),
        @Index(name = "product_material_process_process_type_idx", columnList = "processType"),
        @Index(name = "product_material_process_status_idx", columnList = "status"),
        @Index(name = "product_material_process_suitable_material_type_idx", columnList = "suitableMaterialType")
        }
)
public class MaterialProcessDO implements Serializable {
    private static final long serialVersionUID = -8557406912537496812L;

    /**
     * 主键id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "product_material_process_seq")
    @SequenceGenerator(sequenceName = "product_material_process_seq", name = "product_material_process_seq", allocationSize = 1)
    private Long id;

    /**
     * 创建时间
     */
    @Column(columnDefinition = "timestamp")
    private LocalDateTime createTime;

    /**
     * 会员id
     */
    @Column
    private Long memberId;

    /**
     * 会员角色id
     */
    @Column
    private Long roleId;

    /**
     * 规则名称
     */
    @Column(columnDefinition = "varchar(100)")
    private String name;

    /**
     * 流程类型，
     * 定义在： MaterialProcessTypeEnum
     */
    @Column
    private Integer processType;

    /**
     * 流程key
     */
    @Column
    private String processKey;

    /**
     * 适用物料类型
     * 定义在： MaterialProcessSuitableTypeEnum
     */
    @Column
    private Integer suitableMaterialType;

    /**
     * 状态
     * 定义在： MaterialProcessStatusEnum
     */
    @Column
    private Integer status;

    @ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinColumn(name = "base_material_process_id", referencedColumnName = "id")
    private BaseMaterialProcessDO baseMaterialProcess;

    /**
     * 多对多双向关联物料分组
     * 选中部分物料分组
     */
    @JsonManagedReference
    @ManyToMany
    @JoinTable(name = "product_material_process_rel_material_group",
            joinColumns = {@JoinColumn(name = "material_process_id", referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "material_group_id", referencedColumnName = "id")}
    )
    private List<MaterialGroup> materialGroups;

    /**
     * 多对多双向关联物料
     * 选中部分物料
     */
    @JsonManagedReference
    @ManyToMany
    @JoinTable(name = "product_material_process_rel_material",
            joinColumns = {@JoinColumn(name = "material_process_id", referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "material_id", referencedColumnName = "id")}
    )
    private List<Goods> materials;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public Long getMemberId() {
        return memberId;
    }

    public void setMemberId(Long memberId) {
        this.memberId = memberId;
    }

    public Long getRoleId() {
        return roleId;
    }

    public void setRoleId(Long roleId) {
        this.roleId = roleId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getProcessType() {
        return processType;
    }

    public void setProcessType(Integer processType) {
        this.processType = processType;
    }

    public String getProcessKey() {
        return processKey;
    }

    public void setProcessKey(String processKey) {
        this.processKey = processKey;
    }

    public Integer getSuitableMaterialType() {
        return suitableMaterialType;
    }

    public void setSuitableMaterialType(Integer suitableMaterialType) {
        this.suitableMaterialType = suitableMaterialType;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public BaseMaterialProcessDO getBaseMaterialProcess() {
        return baseMaterialProcess;
    }

    public void setBaseMaterialProcess(BaseMaterialProcessDO baseMaterialProcess) {
        this.baseMaterialProcess = baseMaterialProcess;
    }

    public List<MaterialGroup> getMaterialGroups() {
        return materialGroups;
    }

    public void setMaterialGroups(List<MaterialGroup> materialGroups) {
        this.materialGroups = materialGroups;
    }

    public List<Goods> getMaterials() {
        return materials;
    }

    public void setMaterials(List<Goods> materials) {
        this.materials = materials;
    }
}